package service;

import dao.UserDao;
import model.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class UserService {
    private UserDao userDao = new UserDao();
    private Class aClass = null;

    public User findByUsername(String username) {
        return userDao.findByUsername(username);

    }

    public User findByEmail(String email) {
        return null;
    }

    public void save(User user) {
    }

    public List<User> findAll() {
        return userDao.findAll();
    }

    public PageEntity<User> findPage(Integer currPage, String realName) {
        PageEntity<User> pageModel = new PageEntity<>();
        pageModel.setCurrPage(currPage);
        Integer pageSize = pageModel.getPageSize();
        Integer startIndex = (currPage - 1) * pageSize;
        List<User> data = userDao.findPage(realName, startIndex, pageSize);
        Integer totalCount = userDao.countByRealName(realName);
        Integer totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : (totalCount / pageSize) + 1;
        pageModel.setCurrPage(currPage);
        pageModel.setData(data);
        pageModel.setTotalCount(totalCount);
        pageModel.setTotalPage(totalPage);
        return pageModel;
    }
//    public User UserDetail(Integer id){
//        return userDao.UserDetail(id);
//    }
    public List<Map<String, Object>> findDept() {
        return userDao.findDept();
    }
    public int update(Object[] objects){
        return userDao.update("update user set phone=?,age=?,login_time=?,is_secret=?  where real_name = ?",objects);
    }
    public void updateUrl(Long id, String picUrl) { userDao.updateUrl(id,picUrl); }

    public List<Meeting> meetingList(String realName,Integer i1,Integer i2) {
        return userDao.meetingList(realName,i1,i2);
    }

    public int findCount(String s) {
        return  userDao.findCount(s);
    }

    public Meeting meetDetail(Integer i) {
        return userDao.meetDetail(i);
    }

    public Integer userDetail(Integer i) {
       return userDao.userDetail(i);
    }

    public List<User> toFocus(Integer i) {
        return userDao.toFocus(i);

    }

    public List<Article> showArticle(String name,Integer i1,Integer i2) {
        return userDao.showArticle(name,i1,i2);

    }

    public List<Article> collectActicle(Integer i) {
        return userDao.collectActicle(i);
    }

    public List<Integer> collectCount(Integer id) {
        return userDao.collectCount(id);
    }

    public Integer findByArticlename(String s) {
        return userDao.findByArticlename(s);
    }

    public int addArticle(String title, String content, int i, Date date, String realName, Integer userId) {
        return userDao.addArticle(title,content,i,date,realName,userId);
    }

    public int addMeeting(String s1,Integer i1,String s2,String s3,Date d1,Date d2,Date d3,Integer i2,String s4) {
       return userDao.addMeeting(s1,i1,s2,s3,d1,d2,d3,i2,s4);

    }

    public Article articleDetail(Integer id) {
        return userDao.articleDetail(id);
    }

    public int changeFocus(Integer id,Integer i) {
        return userDao.changeFocus(id,i);
    }

    public int addFocus(Integer userId, Integer id) {
        return userDao.addFocus(userId,id);
    }

    public List<Userfocus> findFocus(Integer userId) {
        return userDao.findFocus(userId);
    }
}


